package object2;


/**
 * instanceOf 比较操作符
 */
public class PolyDetail03 {

    public static void main(String[] args) {

        /*
            instanceOf 比较操作符
            用于判断对象的运行类型是否为XX类型或XX类型的子类型
         */
        PolyDetail03Sub polyDetail03Sub = new PolyDetail03Sub();
        System.out.println(polyDetail03Sub instanceof  PolyDetail03Sub);// true
        System.out.println(polyDetail03Sub instanceof PolyDetail03Base);// true

        //编译类型:PolyDetail03Base 运行类型:PolyDetail03Sub
        PolyDetail03Base polyDetail03Base = new PolyDetail03Sub();
        System.out.println(polyDetail03Base instanceof PolyDetail03Base);//true
        System.out.println(polyDetail03Base instanceof PolyDetail03Sub);//true

        //编译类型 运行类型:Object
        Object obj = new Object();
        System.out.println(obj instanceof PolyDetail03Base);//false
        String str = "hello";
        System.out.println(str instanceof Object);//true str的运行类型 String 是 Object 的子类
    }
}

class PolyDetail03Base {

}

class PolyDetail03Sub extends PolyDetail03Base {

}